package org.example.ch04.service;

import org.apache.ibatis.session.SqlSession;
import org.example.ch04.entity.User;
import org.example.ch04.mapper.UserMapper;
import org.example.ch04.util.MybatisUtils;

/**
 * ClassName: UserService
 * Description:
 *
 * @Author zjl
 * @Create 2025/04/23 10:35
 * @Version 1.0
 */
public class UserService {

    public User getUserById(int id) {
        try (SqlSession sqlSession = MybatisUtils.getSqlSession()) {
            return sqlSession.getMapper(UserMapper.class).getUserById(id);
        }
    }

    public User getUser(String name, int age) {
        try (SqlSession sqlSession = MybatisUtils.getSqlSession()) {
            return sqlSession.getMapper(UserMapper.class).getUser(name, age);
        }
    }
}
